<!doctype html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
	<th:block th:include="/A0723/include :: header('内部转账')"/>
</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">内部转账</h1>
			<a class="head_right" style="color: #f99703 !important;" href="toTransferRecord">记录</a>
		</header>
		<div class="mui-content">
			<div class="forget_from">
				<div class="mui-input-row">
					<label>可用余额：</label>
					<input style="color: #f99703;"  type="text" th:value="${session.appUser.balance}">
				</div>
				<div class="mui-input-row">
					<label>转入账号：</label>
					<input type="text" id="inPhone" placeholder="请输入转入账号">
				</div>
				<div class="mui-input-row">
					<label>转账金额：</label>
					<input type="text" id="money" placeholder="请输入转账金额">
				</div>

			</div>
			<button type="button" onclick="transfer()" class="mui-btn mui-btn-blue mui-btn-block mui_btn">转账</button>
		</div>
		<th:block th:include="/A0723/include :: footer"/>
		<script type="text/javascript">
			let data = {}
			//验证
			function validateTransfer() {
				let money = $("#money").val();
				if (money == null || money === '') {
					mui.toast('请输入转账金额', {duration: 'long', type: 'div'})
					return
				}
				let inPhone = $("#inPhone").val();
				if (inPhone == null || inPhone === '') {
					mui.toast('请输入转入账号', {duration: 'long', type: 'div'})
					return
				}

				data.money = money;
				data.inPhone = inPhone;
				return true;
			}

			//转账
			function transfer() {
				if (validateTransfer()) {
					mui.ajax(ctx+'front/transfer', {
						data: data,
						dataType: 'json',//服务器返回json格式数据
						type: 'post',//HTTP请求类型
						timeout: 10000,//超时时间设置为10秒；
						headers: {'Content-Type': 'application/json'},
						success: function (res) {
							//服务器返回响应，根据响应结果，分析是否登录成功；

							mui.toast(res.msg, {duration: 'long', type: 'div'})
							setInterval(function () {
								window.location.reload()
							},3000)
						},
						error: function (xhr, type, errorThrown) {
							//异常处理；
							console.log(type);
						}
					});
				}
			}
		</script>
	</body>

</html>
